package com.ieasy.module.system.web.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.codec.binary.Base64;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ieasy.basic.util.BaseConst;
import com.ieasy.basic.util.CookieKit;
import com.ieasy.module.common.web.action.BaseController;

@Controller
@RequestMapping("/login")
public class MainController extends BaseController {

	@RequestMapping(value="/main.do", method=RequestMethod.GET)
	public String main(HttpServletRequest request) {
		
		try {
			//获取用户账号Cookie
			String loginKey = CookieKit.getCookieValue(request, BaseConst.COOKIE_NAME_LOGIN_KEY) ;
			if(null != loginKey) {
				String decodeLoginKey = new String(Base64.decodeBase64(loginKey),"utf-8");
				String[] cookieValues = decodeLoginKey.split(":") ;
				if(cookieValues.length == 3) {
					request.setAttribute(BaseConst.COOKIE_NAME_ACCOUNT, cookieValues[0]);
					request.setAttribute(BaseConst.COOKIE_NAME_PASSWORD, cookieValues[1]);
					request.setAttribute(BaseConst.COOKIE_NAME_REMEMBER, true);
				} 
			}else {
				request.setAttribute(BaseConst.COOKIE_NAME_REMEMBER, false);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return "/WEB-INF/security_views/login" ;
	}
	
}
